package heip.generator.main;

import heip.generator.entity.EntityClazz;
import heip.generator.entity.EntityTable;
import heip.generator.entity.TableClazz;
import heip.generator.generer.ActionGenerator;
import heip.generator.generer.ActionGenerator2;
import heip.generator.generer.EntityGenerator;
import heip.generator.generer.JSPGenerator;
import heip.generator.generer.JSPGenerator2;
import heip.generator.generer.ServiceGenerator;
import heip.generator.generer.ServiceGenerator2;


public class TwoTable4GridGenerator2  extends BaseAbstractCodeGenerator{

	private String moduleName = "";//模块名称
	
	public TwoTable4GridGenerator2(String moduleName){
		this.moduleName = moduleName;
		
	}
	
	public void generator(EntityTable table,TableClazz tableClazz) throws Exception {
		//实体
		EntityGenerator eg = new EntityGenerator(moduleName);
		eg.generatorPO(new EntityTable[]{table}, null);
		eg.generatorVO(new EntityTable[]{table}, false);
		
		for(EntityTable et : table.getSubEntitys()){
			eg.generatorPO(new EntityTable[]{et}, null);
			eg.generatorVO(new EntityTable[]{et}, false);
		}
		
		//
		for(EntityTable et : table.getSubEntitys()){
			TableClazz sub = new TableClazz(et.getTableName());
			sub.setFkColumn(et.getFkColumn());
			tableClazz.getSubClazzes().add(sub);
		}
		
		//service
		ServiceGenerator2 sg = new ServiceGenerator2(moduleName);
		sg.generGrid(tableClazz);
		//action
		ActionGenerator2 action = new ActionGenerator2(moduleName);
		action.generatorGrid(tableClazz);
		//jsp
		JSPGenerator2 jsp = new JSPGenerator2(moduleName);
		jsp.generatorGrid(tableClazz);
	}
	
	
	/**
	 * 使用说明
	 * 1)定义子表对象（可以多个）
	 * 例如： 
	 * EntityClazz sub = new EntityClazz(BmCodeName.class,"代码定义","codeType");//参数：子表类Class,实体中文名称，外键属性名
	 * EntityClazz sub2 = new EntityClazz(BmCodeName2.class,"代码定义2","codeType");
	 *
	 * 2)定义主表Entity（只有一个）
	 * 例如 ：
	 * EntityClazz mainClazz = new EntityClazz(BmCodeType.class, "代码类型",sub,sub2);//参数为：类class，中文名称，子表EntityClazz对象,...
	 * 
	 * 3)调用gt(主表EntityClazz)生成文件
	 */
	public void generatorClazzAndJSP()throws Exception{
		//EntityClazz subClazz = new EntityClazz(.class, "","codeType");
		//EntityClazz mainClazz = new EntityClazz(.class, "代码类型",subClazz);
		
		/////////////////////////////////////////////////////////////生成代码
		//gc(mainClazz);//只需要传入主表对象就可以了
	}
	
	
	
	
	
	//////////////////////////下面内容请勿修改/////////////////////////////////
	//////////////////////////下面内容请勿修改/////////////////////////////////
	//////////////////////////下面内容请勿修改/////////////////////////////////
	
	
	private void gc(EntityClazz clazz)throws Exception{
		ServiceGenerator sg = new ServiceGenerator(moduleName);
		sg.generatorGrid(clazz);
		ActionGenerator ag = new ActionGenerator(moduleName);
		ag.generatorGrid(clazz);
		JSPGenerator jg = new JSPGenerator(moduleName);
		jg.generatorGrid(clazz);
	}
}
